package com.moonshineproject.commands
{
	import com.moonshineproject.IDEModel;
	import com.moonshineproject.editor.BasicTextEditor;
	import com.moonshineproject.events.ChangeLineEncodingEvent;
	
	import flash.events.Event;

	public class ChangeLineEndingCommand implements ICommand
	{
		private var model:IDEModel = IDEModel.getInstance();

		public function execute(event:Event):void
		{
			var editor:BasicTextEditor = this.model.activeEditor as BasicTextEditor;
			if (editor)
			{
				var delim:String;
				
				if 	    (event.type == ChangeLineEncodingEvent.EVENT_CHANGE_TO_WIN)  delim = "\r\n";
				else if (event.type == ChangeLineEncodingEvent.EVENT_CHANGE_TO_UNIX) delim = "\n";
				else if (event.type == ChangeLineEncodingEvent.EVENT_CHANGE_TO_OS9)  delim = "\r";
				else { throw new Error("Unknown line delimiter event."); }
				
				editor.getEditorComponent().lineDelim = delim; 
			}
		}
		
	}
}